#include "Camera.h"
#include "Global.h"

CCamera::CCamera()
{
	ViewPort.x = 0;
	ViewPort.y = G_ScreenHeight;
}

D3DXVECTOR3 CCamera::CenterSprite(int x, int y)
{
	D3DXVECTOR3 center = D3DXVECTOR3(x/2, y/2 , 0);
	return center;
}

void CCamera::UpdateCamera(int x)
{
	ViewPort.x = x - 400;
	if(ViewPort.x < 0)
	{
		ViewPort.x = 0;
	}
}

D3DXVECTOR2 CCamera::Transform(int x, int y)
{
	D3DXMATRIX matrix;
	D3DXMatrixIdentity(&matrix);
	matrix._22 = -1;
	matrix._41 = -ViewPort.x;
	matrix._42 = ViewPort.y;

	D3DXVECTOR3 pos3(x, y, 1);
	D3DXVECTOR4 finalMatrix;
	D3DXVec3Transform(&finalMatrix, &pos3, &matrix);

	D3DXVECTOR2 rsMatrix =  D3DXVECTOR2(finalMatrix.x, finalMatrix.y);
	return rsMatrix;
}